package FulbitoFacil.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import FulbitoFacil.excepcion.DAOExcepcion;
import FulbitoFacil.util.ConexionBD;
import FulbitoFacil.modelo.Cancha;

public class CanchaDAO extends BaseDAO {

	public void insertar(Cancha c) throws DAOExcepcion {

		System.out.println("CanchaDAO: insertar()");
		String query = "INSERT INTO cancha(codLocal,nombreCancha,caracteristicasCancha,foto,codHorario) VALUES (?,?,?,?,?)";
		Connection con = null;
		PreparedStatement stmt = null;
		
		try {
			con = ConexionBD.obtenerConexion();
			
			stmt = con.prepareStatement(query);
			stmt.setInt(1,c.getLocal().getCodLocal());
			stmt.setString(2, c.getNombreCancha());
			stmt.setString(3, c.getCaracteristicaCancha());
			stmt.setString(4, c.getFoto());
			stmt.setInt(5,c.getHorario().getCodHorario());
			int i = stmt.executeUpdate();
			if (i != 1) {
				throw new SQLException("No se pudo insertar");
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}

	}

}
